package com.lcm.basic.p7.set;

import java.util.*;

/**
 * @author Coder-lcm
 * @date 2021/4/3
 */
public class SetDemo {
    public static void main(String[] args) {
        HashSet<Integer> hashSet = new HashSet<>(); //无序
        LinkedHashSet<Integer> linkedHashSet = new LinkedHashSet<>(); // FIFO:按照插入的顺序排序： 由链表实现
        TreeSet<Integer> treeSet = new TreeSet<>(); // 内部实现排序，通过比较器来实现

        for (Integer a: Arrays.asList(12,34,56,78,99,32)) {
            hashSet.add(a);
            linkedHashSet.add(a);
            treeSet.add(a);
        }
        System.out.println("HashSet: " + hashSet); // [32, 34, 99, 56, 12, 78]
        System.out.println("LinkedHashSet: " + linkedHashSet); //[12, 34, 56, 78, 99, 32]
        System.out.println("TreeSet: " + treeSet); //[12, 32, 34, 56, 78, 99]
    }
}
